package com.idea.zd.sys.train.thread;

public class YieldThreadTest extends Thread {

    public YieldThreadTest(String name){
        super.setName(name);
    }

    public void run(){
        for(int i =0; i < 50; i ++){
            System.out.println(getName()+" :"+i);

            if(i == 20){
                //暂停线程，当前线程进入到就绪状态，只有优先级高于或同等级别的可以得到执行权
                Thread.yield();
            }


        }
    }

    public static void main(String [] args){
        YieldThreadTest yieldThreadTest = new YieldThreadTest("高优先级");
        //高优先级
        yieldThreadTest.setPriority(Thread.MAX_PRIORITY);
        yieldThreadTest.start();


        YieldThreadTest yieldThreadTest1 = new YieldThreadTest("低优先级");
        //低优先级
        yieldThreadTest1.setPriority(Thread.MIN_PRIORITY);
        yieldThreadTest1.start();



    }
}
